home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / zendisk2.zip / LST11-1.ASM < prev    next >
Assembly Source File  |  1990-02-15  |  2KB  |  63 lines

  1. ;
  2. ; *** Listing 11-1 ***
  3. ;
  4. ; Copies a string to another string, converting all
  5. ; characters to uppercase in the process, using a loop
  6. ; containing LODSB and STOSB.
  7. ;
  8.     jmp    Skip
  9. ;
  10. SourceString    label    word
  11.     db    'This space intentionally left not blank',0
  12. DestString    db    100 dup (?)
  13. ;
  14. ; Copies one zero-terminated string to another string,
  15. ; converting all characters to uppercase.
  16. ;
  17. ; Input:
  18. ;    DS:SI = start of source string
  19. ;    ES:DI = start of destination string
  20. ;
  21. ; Output:
  22. ;    none
  23. ;
  24. ; Registers altered: AL, BX, SI, DI
  25. ;
  26. ; Direction flag cleared
  27. ;
  28. ; Note: Does not handle strings that are longer than 64K
  29. ;    bytes or cross segment boundaries. Does not handle
  30. ;    overlapping strings.
  31. ;
  32. CopyStringUpper:
  33.     mov    bl,'a'    ;set up for fast register-register
  34.     mov    bh,'z'    ; comparisons
  35.     cld
  36. StringUpperLoop:
  37.     lodsb        ;get the next character and
  38.             ; point to the following character
  39.     cmp    al,bl    ;below 'a'?
  40.     jb    IsUpper    ;yes, not lowercase
  41.     cmp    al,bh    ;above 'z'?
  42.     ja    IsUpper    ;yes, not lowercase
  43.     and    al,not 20h ;is lowercase-make uppercase
  44. IsUpper:
  45.     stosb        ;put the uppercase character into
  46.             ; the new string and point to the
  47.             ; following character
  48.     and    al,al    ;is this the zero that marks the
  49.             ; end of the string?
  50.     jnz    StringUpperLoop ;no, do the next character
  51.     ret
  52. ;
  53. Skip:
  54.     call    ZTimerOn
  55.     mov    si,offset SourceString    ;point DS:SI to the
  56.                     ; string to copy from
  57.     mov    di,seg DestString
  58.     mov    es,di            ;point ES:DI to the
  59.     mov    di,offset DestString    ; string to copy to
  60.     call    CopyStringUpper        ;copy & convert to
  61.                     ; uppercase
  62.     call    ZTimerOff
  63.